home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / btoc_v12.lha / BtoCDir / ExplodeStuff / SAS_C / Decrunch30.s < prev    next >
Encoding:
Text File  |  1994-04-27  |  1.6 KB  |  83 lines

  1. ;    Decrunch30.s
  2. ;    -to decrunch data compressed with BtoC v2.5
  3. ;    or uper
  4. ;    Copyright © 1992-1994 by Stefano Reksten
  5. ;
  6.  
  7.     section text,code
  8.  
  9.     xdef    _Decrunch30
  10.  
  11. _Decrunch30
  12.     movem.l    d1-d5/a0-a1,-(sp)    ; save registers
  13.  
  14.     move.l    (a1)+,d0        ; compressed with
  15.     cmp.l    #'BTOC',d0        ; BtoC v2.5
  16.     beq    ok_go            ; or upper ?
  17.     moveq    #0,d0
  18.     bra    end            ; no -> exit
  19.  
  20. ok_go
  21.     move.l    (a1)+,d0        ; d0 = data_size
  22.                     ; or: how many bytes left
  23.                     ; to decrunch.
  24.     move.b    (a1)+,d1        ; d1 = most_used
  25.                     ; d2 = byte_counter
  26.                     ; d3 = current_byte
  27.     moveq    #0,d4
  28.     move.b    (a1)+,d4        ; d4 = max_counter
  29. loop
  30.     cmp.b    (a1),d1            ; if ( *data_ptr!=most_used )
  31.     beq    explode
  32.     move.b    (a1)+,(a0)+        ; *mem_ptr++=*data_ptr++;
  33.     sub.l    #1,d0            ; decrunched++;
  34.     beq    end
  35.     bra    loop
  36.     
  37. explode
  38.     add.l    #1,a1            ; data_ptr++;
  39.     moveq    #0,d2
  40.     move.b    (a1)+,d2        ; byte_counter = *data_ptr++;
  41.     cmp.b    d2,d4            ; if ( byte_counter > max_counter )
  42.     bhi    else
  43.     sub.l    d4,d2            ; byte_counter-=max_counter;
  44.     beq    skip_byt
  45.     move.b    (a1)+,d3        ; current_byte = *data_ptr++;
  46.     bra    expl
  47. skip_byt                ; exploding byte
  48.     move.b    (a1)+,d5        ; procedure.
  49.     moveq    #7,d2
  50.     move.b    d1,(a0)+        ; puts 1 most_used
  51. skip_loop
  52.     btst    d2,d5
  53.     bne    put_byte
  54.     move.b    d1,(a0)+        ; else put most_used
  55.     bra    ok
  56. put_byte
  57.     move.b    (a1)+,(a0)+
  58. ok
  59.     dbra    d2,skip_loop
  60.     sub.l    #9,d0
  61.     bra    done
  62. else
  63.     move.b    d1,d3            ; current_byte = most_used;
  64.  
  65. expl
  66.     sub.l    d2,d0            ; decrunched += byte_counter;
  67.     sub.b    #1,d2
  68. exploop
  69.     move.b    d3,(a0)+        ; *mem_ptr++ = current_byte
  70.     dbra    d2,exploop        ; while ( byte_counter-- )
  71.  
  72. done
  73.     tst.l    d0
  74.     beq    all_done
  75.     bra    loop
  76. all_done
  77.     moveq    #1,d0
  78. end
  79.     movem.l    (sp)+,d1-d5/a0-a1
  80.     rts
  81.  
  82.     END
  83.